home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / DBMSGEN.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  33.6 KB  |  708 lines

  1. rem
  2. rem $Header: dbmsgen.sql 7020200.1 95/02/15 18:31:49 cli Generic<base> $ 
  3. rem
  4. Rem  Copyright (c) 1993 by Oracle Corporation 
  5. Rem    NAME
  6. Rem     dbmsgen.sql - Replication code generators.
  7. Rem          
  8. Rem    DESCRIPTION
  9. Rem     Routines to generate shadow tables, triggers, and packages for
  10. Rem     table replication.
  11. Rem     Routines to generate wrappers for replication of standalone procedure
  12. Rem     invocations, and packaged procedure invocations.
  13. Rem     Routines which support generated replication code.  
  14. Rem    
  15. Rem    RETURNS
  16. Rem     None
  17. Rem     
  18. Rem    NOTES
  19. Rem      The procedural option is needed to use this facility.
  20. Rem
  21. Rem      This package is installed by sys (connect internal).
  22. Rem
  23. Rem    MODIFIED   (MM/DD/YY)
  24. Rem     jstamos    11/11/94 -  merge changes from branch 1.1.710.7
  25. Rem     adowning   10/13/94 -  merge rev 1.1.710.4
  26. Rem     adowning   09/21/94 -  improved comments
  27. Rem     ldoo       08/18/94 -  Changed to use columns in the column group
  28. Rem                            instead of parameter columns in the if
  29. Rem                            ignore_discard_flag then section of user funcs.
  30. Rem     adowning   08/10/94 -  Move dbms_maint_gen to prvt from dbms
  31. Rem     ldoo       07/19/94 -  Took out FLOAT as a valid column datatype.
  32. Rem     ldoo       06/23/94 -  Added automatic conflict resolution.
  33. Rem     ldoo       05/09/94 -  Changed the generated trigger by replacing
  34. Rem                            dbms_defer arg calls with dbms_reputil arg
  35. Rem                            calls.  Hence reduce size and enhance speed.
  36. Rem                            Added arg call procedures in dbms_reputil pkg.
  37. Rem     ldoo       03/02/94 -  The argument$.type for ROWID is 69 not 11.
  38. Rem                         -  Default for generate_wrapper_package.procedure_
  39. Rem                            prefix should be NULL.
  40. Rem                         -  Proper error message for attempt to wrap func.
  41. Rem     ldoo       02/25/94 -  Fixed plsql parser bug workaround.
  42. Rem                         -  Do not validate generate_trigger.package_name.
  43. Rem     ldoo       02/18/94 -  Skip LONG and LONG RAW columns in row/col repl.
  44. Rem                         -  Fixed hanging is_dest_node_provided function.
  45. Rem     ldoo       02/17/94 -  Workaround plsql parser bug by adding () to
  46. Rem                            every ten AND clauses in the generated package.
  47. Rem     ldoo       01/21/94 -  Fixed to support mixed-case object names.
  48. Rem     ldoo       01/18/94 -  Added 2 more in parameters to 
  49. Rem                              generate_wrapper_package.
  50. Rem                            Use array parsing.
  51. Rem                            Removed commit statement.
  52. Rem                            Replaced some functions with shared ones.
  53. Rem     ldoo       12/17/93 -  Fixed bug about having extra ');' for
  54. Rem                              column-level replication.
  55. Rem                            Fixed bug about not preserving user-assigned
  56. Rem                              package_name and trigger_name.  
  57. Rem                            Uppercased 'p', '$rp', 't' and '$rt'.
  58. Rem                            Validated IN parameter values.
  59. Rem                            Defaulted USER if output_table is not prefixed
  60. Rem                              with schema name.
  61. Rem                            Double quoted column names in generated trigger.
  62. Rem                            Modified already_exists() to use dba views. 
  63. Rem                            Loop until generated package/trigger name is
  64. Rem                              unique.
  65. Rem     ldoo       10/18/93 -  Eliminated IN OUT parameters.  Supports Remote-
  66. Rem                            Only, Synchronous, and Mixed Replications. 
  67. Rem     dsdaniel   09/01/93 -  split into multiple packages, merged in dbmsrepu
  68. Rem     ldoo       08/25/93 -  Coded to the 8/20 version of spec.
  69. Rem     bsouder    08/13/93 -  minor beautification, corrected dbms_snapshot
  70. Rem                            call
  71. Rem     celsbern   08/13/93 -  added comments
  72. Rem     ldoo       08/13/93 -  Creation to RDBMS spec.
  73.  
  74. CREATE OR REPLACE PACKAGE dbms_defergen IS
  75.  
  76.   ------------
  77.   --  OVERVIEW
  78.   -- 
  79.   --  This package provides support for the generation of triggers and 
  80.   --  procedures used in table replication, updatable snapshots, and 
  81.   --  invocation replication of procedures and packages. 
  82.   --  Use of the replication catalog and the output of this package provide
  83.   --  a asynchronous replication of data between different databases.
  84.  
  85.   -----------------
  86.   --  NEW DATATYPES
  87.   --
  88.   TYPE V128Tab IS TABLE OF VARCHAR2(128)
  89.     INDEX BY BINARY_INTEGER;
  90.   -- Used as temporary storage of destination node names.
  91.  
  92.   TYPE V92Tab IS TABLE OF VARCHAR2(92)
  93.     INDEX BY BINARY_INTEGER;
  94.   -- Used as temporary storage of conflict resolution routine names.
  95.  
  96.   TYPE V30Tab IS TABLE OF VARCHAR2(30)
  97.     INDEX BY BINARY_INTEGER;
  98.   -- Used as temporary storage of column names, table names, package names,
  99.   -- procedure names and data types as each trigger or procedure is 
  100.   -- built.  
  101.  
  102.   TYPE V1Tab IS TABLE OF VARCHAR2(1)
  103.     INDEX BY BINARY_INTEGER;
  104.   -- Used as temporary storage of flag whether columns are nullable or not.
  105.  
  106.   TYPE BoolTab IS TABLE OF BOOLEAN
  107.     INDEX BY BINARY_INTEGER;
  108.   -- Used to pass switches to control various generator options.
  109.  
  110.   TYPE NumTab IS TABLE OF NUMBER
  111.     INDEX BY BINARY_INTEGER;
  112.   -- Used as temporary storage of column lengths and procedure overload number.
  113.  
  114.  
  115.   --------------------
  116.   --  GLOBAL VARIABLES
  117.   --
  118.   INIT_V128Tab V128Tab;  -- Used to default list of destination node names.
  119.  
  120.  
  121.   -----------------
  122.   -- ERROR MESSAGES
  123.   --
  124.   missschema_num NUMBER := -23306;
  125.   -- "schema %s does not exist"
  126.  
  127.   missobj_num NUMBER := -23308;
  128.   -- "object %s does not exist or is invalid"
  129.  
  130.   misspk_num NUMBER := -23346;
  131.   -- "primary key is undefined for table %s"
  132.  
  133.   datatypefail_num NUMBER := -23347;
  134.   -- "datatype %s for column \"%s\" table %s not supported"
  135.  
  136.   pmodefail_num NUMBER := -23348;
  137.   -- "cannot replicate procedure %s; only IN parameters supported"
  138.  
  139.   progfail_num NUMBER := -23349;
  140.   -- "cannot generate replication support for functions"
  141.  
  142.   recurfail_num NUMBER := -23350;
  143.   -- "maximum number of recursive calls exceeded"
  144.  
  145.   ptypefail_num NUMBER := -23351;
  146.   -- "parameter datatype %s for procedure %s not supported"
  147.  
  148.   ----------------------------
  149.   --  PROCEDURES AND FUNCTIONS
  150.   --
  151.   PROCEDURE create_audit_table(table_schema  IN  VARCHAR2,
  152.                                table_name    IN  VARCHAR2,
  153.                                audit_table   IN  VARCHAR2,
  154.                                key_columns   IN  V30Tab,
  155.                                do_ddl        IN  BOOLEAN,
  156.                                output_table  IN  VARCHAR2,
  157.                                name_assigned OUT VARCHAR2);
  158.   -- Create a shadow table for the given table if necessary.  
  159.   -- Input parameters:
  160.   --  schema_name The name of the schema containing the table to be
  161.   --    replicated.  Defaults to invoking user.
  162.   --  table_name The name of the table being replicated.
  163.   --  audit_table The name to be assigned to the shadow table being
  164.   --    created.  If null, the shadow table name is generated.
  165.   --  key_columns List of columns that constitute the primary key for the
  166.   --    shadow table.  If null, the database dictionary is used to
  167.   --    determine the primary key.
  168.   --  do_ddl If TRUE (the default) the DDL generated is executed.  If FALSE,
  169.   --    then output_table should be specified so that the DDL generated
  170.   --    will be saved in a table.  
  171.   --  output_table The name of the table to write the DDL to (if not NULL). 
  172.   --    The table must have a format compatible with the following:
  173.   --
  174.   --                  Column Name  Data Type
  175.   --                  -----------  ---------
  176.   --                  name         varchar2(30)
  177.   --                  type         varchar2(12)
  178.   --                  linenum      number
  179.   --                  text         varchar2(255)
  180.   --
  181.   --    Both do_ddl and an output table may be specified.  
  182.   -- Output parameter:
  183.   --  name_assigned The name actually assigned to the shadow table.  Because
  184.   --    of conflicts, this is not always predictable if the audit_table
  185.   --    input is not specified.  This value is needed as input to both
  186.   --    generate_package and generate_triggers procedures.
  187.   -- Exceptions: TBD
  188.  
  189.   PROCEDURE alter_audit_table(table_schema  IN     VARCHAR2,
  190.                               audit_table   IN     VARCHAR2,
  191.                               do_ddl        IN     BOOLEAN,
  192.                               output_table  IN     VARCHAR2,
  193.                               ddl_string    IN OUT dbms_sys_sql.varchar2s);
  194.   -- Modify the given shadow table if necessary.  New columns may be added to
  195.   -- the shadow table.  
  196.   -- Input parameters:
  197.   --  schema_name The name of the schema containing the table to be replicated.
  198.   --    Defaults to invoking user.
  199.   --  table_name The name of the table being replicated.
  200.   --  audit_table The name of the shadow table.  
  201.   --  do_ddl If TRUE (the default) the DDL generated is executed.  If FALSE,
  202.   --    then output_table should be specified so that the DDL generated
  203.   --    will be saved in a table.  
  204.   --  output_table The name of the table to write the DDL to (if not NULL). 
  205.   --    The table must have a format compatible with the following:
  206.   --
  207.   --                  Column Name  Data Type
  208.   --                  -----------  ---------
  209.   --                  name         varchar2(30)
  210.   --                  type         varchar2(12)
  211.   --                  linenum      number
  212.   --                  text         varchar2(255)
  213.   --
  214.   --    Both do_ddl and an output table may be specified.  
  215.   -- Output parameter:
  216.   --  ddl_string The DDL string for altering the shadow table.  
  217.   -- Exceptions: TBD
  218.  
  219.   PROCEDURE generate_audit_package(table_schema          IN  VARCHAR2,
  220.                                    table_name            IN  VARCHAR2,
  221.                                    package_name          IN  VARCHAR2,
  222.                                    do_ddl                IN  BOOLEAN,
  223.                                    output_table          IN  VARCHAR2,
  224.                                    name_assigned         OUT VARCHAR2);
  225.   -- For the given table, generate the package that contains just package
  226.   -- variables used for passing old audit column values from the replication
  227.   -- update procedure to the replication trigger.  
  228.   -- Input parameters:
  229.   --  schema_name The name of the schema containing the table to be replicated.
  230.   --    Defaults to invoking user.
  231.   --  table_name The name of the table being replicated.
  232.   --  package_name The name to be assigned to the package being created.  
  233.   --    If null, the package name is generated.  If non-null,
  234.   --    CREATE OR REPLACE PACKAGE is used to replace the package
  235.   --    even if a package with that name already exists.
  236.   --  do_ddl If TRUE (the default) the DDL generated is executed.  If FALSE,
  237.   --    then output_table should be specified so that the DDL generated
  238.   --    will be saved in a table.  
  239.   --  output_table The name of the table to write the DDL to (if not NULL). 
  240.   --    The table must have a format compatible with the following:
  241.   --
  242.   --                  Column Name  Data Type
  243.   --                  -----------  ---------
  244.   --                  name         varchar2(30)
  245.   --                  type         varchar2(12)
  246.   --                  linenum      number
  247.   --                  text         varchar2(255)
  248.   --
  249.   --    Both do_ddl and an output table may be specified.  
  250.   -- Output parameter:
  251.   --  name_assigned The name actually assigned to the package.  Because of
  252.   --    conflicts, this is not always predictable if the
  253.   --    package_name input is not specified.  This value is needed
  254.   --    as input to both generate_package and generate_triggers
  255.   --    procedures.
  256.   -- Exceptions: TBD
  257.  
  258.   PROCEDURE generate_priority_package(table_schema          IN  VARCHAR2,
  259.                                       package_name          IN  VARCHAR2,
  260.                                       do_ddl                IN  BOOLEAN,
  261.                                       output_table          IN  VARCHAR2,
  262.                                       name_assigned         OUT VARCHAR2);
  263.   -- Generate the package that contains functions used for resolving conflicts
  264.   -- by priority groups.    
  265.   -- Input parameters:
  266.   --  schema_name The name of the repschema.  Defaults to invoking user.
  267.   --  package_name The name to be assigned to the package being created.  If
  268.   --    null, the package name is generated.  If non-null,
  269.   --    CREATE OR REPLACE PACKAGE is used to replace the package
  270.   --    even if a package with that name already exists.
  271.   --  do_ddl If TRUE (the default) the DDL generated is executed.  If FALSE,
  272.   --    then output_table should be specified so that the DDL generated
  273.   --    will be saved in a table.  
  274.   --  output_table The name of the table to write the DDL to (if not NULL).
  275.   --    The table must have a format compatible with the following:
  276.   --
  277.   --                  Column Name  Data Type
  278.   --                  -----------  ---------
  279.   --                  name         varchar2(30)
  280.   --                  type         varchar2(12)
  281.   --                  linenum      number
  282.   --                  text         varchar2(255)
  283.   --
  284.   --    Both do_ddl and an output table may be specified.  
  285.   -- Output parameter:
  286.   --  name_assigned The name actually assigned to the package.  Because of
  287.   --    conflicts, this is not always predictable if the
  288.   --    package_name input is not specified.  This value is needed
  289.   --    as input to generate_resolution_package procedure.  
  290.   -- Exceptions: TBD
  291.  
  292.   PROCEDURE generate_package(table_schema       IN  VARCHAR2,
  293.                              table_name         IN  VARCHAR2,
  294.                              repl_package       IN  VARCHAR2,
  295.                              reso_package       IN  VARCHAR2,
  296.                              key_columns        IN  V30Tab,
  297.                              audit_table        IN  VARCHAR2,
  298.                              audit_package      IN  VARCHAR2,
  299.   --                           ins_conflict_proc IN  V92Tab,
  300.   --                           upd_conflict_proc IN  V92Tab,
  301.   --                           del_conflict_proc IN  V92Tab,
  302.                              do_ddl             IN  BOOLEAN,
  303.                              output_table       IN  VARCHAR2,
  304.                              repl_name_assigned OUT VARCHAR2,
  305.                              reso_name_assigned OUT VARCHAR2);
  306.   -- Generate the replication package for a table.  
  307.   -- Input parameters:
  308.   --  table_schema The name of the schema containing the table to be
  309.   --    replicated.  Defaulting to invoking user.  
  310.   --  table_name The name of the table being replicated.  
  311.   --  repl_package The name to be assigned to the replication package being
  312.   --    created.  If null, the package name is generated.  If non-null,
  313.   --    CREATE OR REPLACE PACKAGE is used to replace the package even if a
  314.   --    package with that name already exists.  
  315.   --  reso_package The name to be assigned to the resolution package being
  316.   --    created.  If null, the package name is generated.  If non-null,
  317.   --    CREATE OR REPLACE PACKAGE is used to replace the package even if a
  318.   --    package with that name already exists.  
  319.   --  key_columns List of columns that constitute the primary key for the
  320.   --    replicated table.  If null, the database dictionary is used to
  321.   --    determine the primary key.  
  322.   --  audit_table The name of the shadow table if automatic generation of
  323.   --    audit information is required. 
  324.   --  audit_package The name of audit package if automatic generation of
  325.   --    audit information is required.  
  326.   --  do_ddl If TRUE (the default) the DDL generated is executed.  If FALSE,
  327.   --    then output_table should be specified so the DDL generated will be
  328.   --    saved in a table. 
  329.   --  output_table The name of the table to write the DDL to (if not NULL). 
  330.   --    The table must have a format compatible with the following:
  331.   --
  332.   --                  Column Name  Data Type
  333.   --                  -----------  ---------
  334.   --                  name         varchar2(30)
  335.   --                  type         varchar2(12)
  336.   --                  linenum      number
  337.   --                  text         varchar2(255)
  338.   --
  339.   --    Both do_ddl and an output table may be specified. 
  340.   --  Output parameters:
  341.   --   repl_name_assigned The name actually assigned to the replication
  342.   --     package.  Because of conflicts, this is not always predictable if the
  343.   --     repl_package input is not specified.  This value is needed as input to
  344.   --     generate_triggers. 
  345.   --   reso_name_assigned The name actually assigned to the resolution
  346.   --     package.  Because of conflicts, this is not always predictable if the
  347.   --     reso_package input is not specified. 
  348.   -- Exceptions: TBD
  349.  
  350.   PROCEDURE generate_triggers(table_schema  IN  VARCHAR2,
  351.                               table_name    IN  VARCHAR2,
  352.                               trigger_name  IN  VARCHAR2,
  353.                               package_name  IN  VARCHAR2,
  354.                               key_columns   IN  V30Tab,
  355.                               audit_table   IN  VARCHAR2,
  356.                               audit_package IN  VARCHAR2,
  357.                               do_ddl        IN  BOOLEAN,
  358.                               output_table  IN  VARCHAR2,
  359.                               name_assigned OUT VARCHAR2,
  360.                               dest_node     IN  V128Tab default INIT_V128Tab);
  361.   -- Generate the replication trigger for a table.
  362.   -- Input parameters:
  363.   --  table_schema The name of the schema containing the table to be
  364.   --    replicated.  Defaulting to invoking user.  
  365.   --  table_name The name of the table being replicated. 
  366.   --  trigger_name The name to be assigned to the trigger being created. If
  367.   --    null, the trigger name is generated.  If not null, the trigger will
  368.   --    replace an existing trigger with the same name. 
  369.   --  package_name The name of the package that the generated triggers defer
  370.   --    calls to.  If null, the name is derived from the table name. 
  371.   --  key_columns List of columns that constitute the primary key for the
  372.   --    replicated table.  If null, the database dictionary is used to
  373.   --    determine the primary key.  
  374.   --  audit_table The name of the shadow table if automatic generation of
  375.   --    audit information is required. 
  376.   --  audit_package The name of audit package if automatic generation of
  377.   --    audit information is required. 
  378.   --  do_ddl If TRUE (the default) the DDL generated is executed.  If FALSE,
  379.   --    then output_table should be specified so the DDL generated will be
  380.   --    saved in a table. 
  381.   --  output_table The name of the table to write the DDL to (if not NULL).
  382.   --    The table must have a format compatible with the following:
  383.   --
  384.   --                  Column Name  Data Type
  385.   --                  -----------  ---------
  386.   --                  name         varchar2(30)
  387.   --                  type         varchar2(12)
  388.   --                  linenum      number
  389.   --                  text         varchar2(255)
  390.   --
  391.   --    Both do_ddl and an output table may be specified. 
  392.   --  dest_node If synchronously replicated, specify here the list of
  393.   --    destination nodes; otherwise, leave it NULL. 
  394.   -- Output parameter:
  395.   --  name_assigned The name actually assigned to the trigger.  Because of
  396.   --    conflicts, this is not always predictable if the trigger_name input is
  397.   --    not specified.  
  398.   -- Exceptions: TBD
  399.  
  400.   PROCEDURE generate_wrapper_package(sname            IN  VARCHAR2,
  401.                                      pkg              IN  VARCHAR2,
  402.                                      package_prefix   IN  VARCHAR2,
  403.                                      procedure_prefix IN  VARCHAR2,
  404.                                      do_ddl           IN  BOOLEAN,
  405.                                      output_table     IN  VARCHAR2,
  406.                                      generate_package IN  BOOLEAN,
  407.                                      generate_body    IN  BOOLEAN,
  408.                                      name_assigned    OUT VARCHAR2,
  409.                                      call_local       IN  BOOLEAN
  410.                                                                  default FALSE,
  411.                                      mixed_replmethod IN  BOOLEAN
  412.                                                                  default FALSE,
  413.                                      dest_node        IN  V128Tab
  414.                                                          default INIT_V128Tab);
  415.   -- Generate a wrapper package for the given package.
  416.   -- Input parameters:
  417.   --  sname The name of the replicated schema.  Defaulting to invoking user.  
  418.   --  pkg The replicated package. 
  419.   --  package_prefix The prefix for the new package.  Defaulting to 'DEFER_'.
  420.   --  procedure_prefix The prefix for each new procedure.
  421.   --  do_ddl If TRUE (the default) the DDL generated is executed.  If FALSE,
  422.   --    then output_table should be specified so the DDL generated will be
  423.   --    saved in a table. 
  424.   --  output_table The name of the table to write the DDL to (if not NULL).
  425.   --    The table must have a format compatible with the following:
  426.   --
  427.   --                  Column Name  Data Type
  428.   --                  -----------  ---------
  429.   --                  name         varchar2(30)
  430.   --                  type         varchar2(12)
  431.   --                  linenum      number
  432.   --                  text         varchar2(255)
  433.   --
  434.   --    Both do_ddl and an output table may be specified. 
  435.   --  generate_package If FALSE, do not generate the package specification.
  436.   --    Default to TRUE, generate the package specification.
  437.   --  generate_body If FALSE, do not generate the package body.  Default to
  438.   --    TRUE, generate the package body.
  439.   --  call_local If TRUE, the generated code will call the package locally.
  440.   --    Default to FALSE, the generated code will not call the package locally.
  441.   --  mixed_replmethod If TRUE, the generated code allows mixing of table
  442.   --    replication and procedure invocation replication.   Default to FALSE.
  443.   --  dest_node If synchronously replicated, specify here the list of
  444.   --    destination nodes; otherwise, leave it NULL. 
  445.   -- Output parameter:
  446.   --  name_assigned The name actually assigned to the new package.  Because of
  447.   --    conflicts, this is not always predictable if the package_prefix 
  448.   --    input is not specified.  
  449.   -- Exceptions: TBD
  450.  
  451.   PROCEDURE generate_wrapper_procedure(sname            IN  VARCHAR2,
  452.                                        proc             IN  VARCHAR2,
  453.                                        prefix           IN  VARCHAR2,
  454.                                        do_ddl           IN  BOOLEAN,
  455.                                        output_table     IN  VARCHAR2,
  456.                                        name_assigned    OUT VARCHAR2,
  457.                                        call_local       IN  BOOLEAN
  458.                                                                  default FALSE,
  459.                                        mixed_replmethod IN  BOOLEAN
  460.                                                                  default FALSE,
  461.                                        dest_node        IN  V128Tab
  462.                                                          default INIT_V128Tab);
  463.   -- Generate a wrapper procedure for the given procedure.
  464.   -- Input parameters:
  465.   --  sname The name of the replicated schema.  Defaulting to invoking user.  
  466.   --  proc The replicated procedure. 
  467.   --  prefix The prefix for the wrapper procedure.
  468.   --  do_ddl If TRUE (the default) the DDL generated is executed.  If FALSE,
  469.   --    then output_table should be specified so the DDL generated will be
  470.   --    saved in a table. 
  471.   --  output_table The name of the table to write the DDL to (if not NULL).
  472.   --    The table must have a format compatible with the following:
  473.   --
  474.   --                  Column Name  Data Type
  475.   --                  -----------  ---------
  476.   --                  name         varchar2(30)
  477.   --                  type         varchar2(12)
  478.   --                  linenum      number
  479.   --                  text         varchar2(255)
  480.   --
  481.   --    Both do_ddl and an output table may be specified. 
  482.   --  call_local If TRUE, the generated code will call the package locally.
  483.   --    Default to FALSE, the generated code will not call the package locally.
  484.   --  mixed_replmethod If TRUE, the generated code allows mixing of table
  485.   --    replication and procedure invocation replication.   Default to FALSE.
  486.   --  dest_node If synchronously replicated, specify here the list of
  487.   --    destination nodes; otherwise, leave it NULL. 
  488.   -- Output parameter:
  489.   --  name_assigned The name actually assigned to the wrapper procedure.
  490.   --    Because of conflicts, this is not always predictable if the prefix 
  491.   --    input is not specified.  
  492.   -- Exceptions: TBD
  493.  
  494. END dbms_defergen;
  495. /
  496.  
  497. DROP PUBLIC SYNONYM dbms_defergen;
  498.  
  499. CREATE PUBLIC SYNONYM dbms_defergen for dbms_defergen;
  500.  
  501. CREATE OR REPLACE PACKAGE dbms_reputil AS
  502.  
  503.   ------------
  504.   --  OVERVIEW
  505.   --
  506.   --  This package is referenced only by the generated code.
  507.  
  508.   -------------------
  509.   -- GLOBAL VARIABLES
  510.   --
  511.   replication_is_on BOOLEAN;  -- If false, do not forward/defer the update.
  512.   from_remote BOOLEAN;        -- If false, the update is local.
  513.   global_name VARCHAR2(128);  -- The global name of the local database.
  514.  
  515.   ---------------------------
  516.   -- PROCEDURES AND FUNCTIONS
  517.   --
  518.   PROCEDURE replication_on;
  519.   -- Turn on replication.
  520.  
  521.   PROCEDURE replication_off;
  522.   -- Turn off replication.
  523.  
  524.   --
  525.   -- Automatic conflict resolution logic.
  526.   --
  527.   PROCEDURE recursion_on;
  528.   -- Keep track of the number of recursion.  
  529.  
  530.   PROCEDURE recursion_off;
  531.   -- The number of recursion is initialized to zero.
  532.  
  533.   PROCEDURE rep_begin;
  534.   -- Initialization at the beginning of each rep_delete, rep_insert, and 
  535.   -- rep_update.
  536.  
  537.   PROCEDURE rep_end;
  538.   -- Clean up at the end of each rep_delete, rep_insert, and rep_update.
  539.  
  540.   FUNCTION get_constraint_name(errmsg IN VARCHAR2)
  541.     RETURN VARCHAR2;
  542.   -- Return the name of the uniqueness contraint in the ORA error message. 
  543.  
  544.   FUNCTION minimum(new                 IN  NUMBER,
  545.                    cur                 IN  NUMBER,
  546.                    ignore_discard_flag OUT BOOLEAN)
  547.     RETURN BOOLEAN;
  548.   -- If new > cur, then ignore_discard_flag is TRUE; otherwise it is FALSE.
  549.   -- Return FALSE if any input parameter is null; otherwise return TRUE.
  550.  
  551.   FUNCTION minimum(new                 IN  VARCHAR2,
  552.                    cur                 IN  VARCHAR2,
  553.                    ignore_discard_flag OUT BOOLEAN)
  554.     RETURN BOOLEAN;
  555.   -- If new > cur, then ignore_discard_flag is TRUE; otherwise it is FALSE.
  556.   -- Return FALSE if any input parameter is null; otherwise return TRUE.
  557.  
  558.   FUNCTION minimum(new                 IN  DATE,
  559.                    cur                 IN  DATE,
  560.                    ignore_discard_flag OUT BOOLEAN)
  561.     RETURN BOOLEAN;
  562.   -- If new > cur, then ignore_discard_flag is TRUE; otherwise it is FALSE.
  563.   -- Return FALSE if any input parameter is null; otherwise return TRUE.
  564.  
  565.   FUNCTION maximum(new                 IN  NUMBER,
  566.                    cur                 IN  NUMBER,
  567.                    ignore_discard_flag OUT BOOLEAN)
  568.     RETURN BOOLEAN;
  569.   -- If new < cur, then ignore_discard_flag is TRUE; otherwise it is FALSE.
  570.   -- Return FALSE if any input parameter is null; otherwise return TRUE.
  571.  
  572.   FUNCTION maximum(new                 IN  VARCHAR2,
  573.                    cur                 IN  VARCHAR2,
  574.                    ignore_discard_flag OUT BOOLEAN)
  575.     RETURN BOOLEAN;
  576.   -- If new < cur, then ignore_discard_flag is TRUE; otherwise it is FALSE.
  577.   -- Return FALSE if any input parameter is null; otherwise return TRUE.
  578.  
  579.   FUNCTION maximum(new                 IN  DATE,
  580.                    cur                 IN  DATE,
  581.                    ignore_discard_flag OUT BOOLEAN)
  582.     RETURN BOOLEAN;
  583.   -- If new < cur, then ignore_discard_flag is TRUE; otherwise it is FALSE.
  584.   -- Return FALSE if any input parameter is null; otherwise return TRUE.
  585.  
  586.   FUNCTION average(new                 IN OUT NUMBER,
  587.                    cur                 IN     NUMBER,
  588.                    ignore_discard_flag OUT    BOOLEAN)
  589.     RETURN BOOLEAN;
  590.   -- Output new as the average of new + old.
  591.   -- Ignore_discard_flag is always FALSE.
  592.   -- Return FALSE if any input parameter is null; otherwise return TRUE.
  593.  
  594.   FUNCTION additive(old                 IN     NUMBER,
  595.                     new                 IN OUT NUMBER,
  596.                     cur                 IN     NUMBER,
  597.                     ignore_discard_flag OUT    BOOLEAN)
  598.     RETURN BOOLEAN;
  599.   -- Output new as cur + (new - old).  Ignore_discard_flag is always FALSE.
  600.   -- Return FALSE if any input parameter is null; otherwise return TRUE.
  601.  
  602.   FUNCTION discard(ignore_discard_flag OUT BOOLEAN)
  603.     RETURN BOOLEAN;
  604.   -- Ignore_discard_flag is always TRUE.
  605.   -- Always return TRUE.
  606.  
  607.   FUNCTION overwrite(ignore_discard_flag OUT BOOLEAN)
  608.     RETURN BOOLEAN;
  609.   -- Ignore_discard_flag is always FALSE.
  610.   -- Always return TRUE.
  611.  
  612.   FUNCTION append_site_name(new                 IN OUT VARCHAR2,
  613.                             str                 IN     VARCHAR2,
  614.                             max_len             IN     NUMBER,
  615.                             ignore_discard_flag OUT    BOOLEAN)
  616.     RETURN BOOLEAN;
  617.   -- Output new with str appended to it. Ignore_discard_flag is always FALSE.
  618.   -- Return FALSE if any input parameter is null or the length of str plus one
  619.   -- is greater than max_len; otherwise return TRUE.
  620.  
  621.   FUNCTION append_sequence(new                 IN OUT VARCHAR2,
  622.                            max_len             IN     NUMBER,
  623.                            ignore_discard_flag OUT    BOOLEAN)
  624.     RETURN BOOLEAN;
  625.   -- Output new with a sequence generated number appended to it.
  626.   -- Ignore_discard_flag is always FALSE.  
  627.   -- Return FALSE if any input parameter is null or the length of the generated
  628.   -- number is greater than max_len; otherwise return TRUE.
  629.  
  630.   --
  631.   -- A hack to make the trigger smaller and run faster.
  632.   --
  633.   PROCEDURE number_arg   (old  IN NUMBER,
  634.                           new  IN NUMBER,
  635.                           flag IN CHAR);
  636.   -- Cover routine for dbms_defer.number_arg.  Using flag to determine whether
  637.   -- to defer old or new or both.  Valid flag values are: 'I', 'D', and 'U'.
  638.  
  639.   PROCEDURE date_arg     (old  IN DATE,
  640.                           new  IN DATE,
  641.                           flag IN CHAR);
  642.   -- Cover routine for dbms_defer.date_arg.  Using flag to determine whether
  643.   -- to defer old or new or both.  Valid flag values are: 'I', 'D', and 'U'.
  644.  
  645.   PROCEDURE varchar2_arg (old  IN VARCHAR2,
  646.                           new  IN VARCHAR2,
  647.                           flag IN CHAR);
  648.   -- Cover routine for dbms_defer.varchar2_arg. Using flag to determine whether
  649.   -- to defer old or new or both.  Valid flag values are: 'I', 'D', and 'U'.
  650.  
  651.   PROCEDURE char_arg     (old  IN CHAR,
  652.                           new  IN CHAR,
  653.                           flag IN CHAR);
  654.   -- Cover routine for dbms_defer.char_arg.  Using flag to determine whether
  655.   -- to defer old or new or both.  Valid flag values are: 'I', 'D', and 'U'.
  656.  
  657.   PROCEDURE rowid_arg    (old  IN ROWID,
  658.                           new  IN ROWID,
  659.                           flag IN CHAR);
  660.   -- Cover routine for dbms_defer.rowid_arg.  Using flag to determine whether
  661.   -- to defer old or new or both.  Valid flag values are: 'I', 'D', and 'U'.
  662.  
  663.   PROCEDURE raw_arg      (old  IN RAW,
  664.                           new  IN RAW,
  665.                           flag IN CHAR);
  666.   -- Cover routine for dbms_defer.raw_arg.  Using flag to determine whether
  667.   -- to defer old or new or both.  Valid flag values are: 'I', 'D', and 'U'.
  668.  
  669.   PROCEDURE enter_statistics(sname             IN VARCHAR2,
  670.                              oname             IN VARCHAR2,
  671.                              conflict_type     IN VARCHAR2,
  672.                              reference_name    IN VARCHAR2,
  673.                              method_name       IN VARCHAR2,
  674.                              function_name     IN VARCHAR2,
  675.                              priority_group    IN VARCHAR2,
  676.                              primary_key_value IN VARCHAR2,
  677.                              resolved_date     IN DATE default SYSDATE);
  678.   -- Record that the given conflict has been resolved with the given
  679.   -- resolution.
  680.   -- Input parameters:
  681.   --  sname The name of the schema containing the table to be replicated.
  682.   --  oname The name of the table being replicated.
  683.   --  conflict_type The type of conflict.  Valid values are: `UPDATE',
  684.   --    `UNIQUENESS', and `DELETE'.
  685.   --  reference_name If the conflict type is 'DELETE', enter the replicated
  686.   --    table name here.  If the conflict type is `UPDATE', enter the column
  687.   --    group name here.  If the conflict type is `UNIQUE CONSTRAINT', enter
  688.   --    the unique constraint name here.
  689.   --  method_name The conflict resolution method.
  690.   --  function_name If the method is 'USER FUNCTION', enter the user
  691.   --    resolution function name here.
  692.   --  priority_group If the method is `PRIORITY GROUP', enter the name of
  693.   --    priority group used for resolving the conflict.
  694.   --  primary_key_value The primary key value for the row whose conflict is
  695.   --    being resolved.  
  696.   --  resolved_date The date at which the conflict is resolved.  
  697.  
  698. END dbms_reputil;
  699. /
  700.  
  701. DROP PUBLIC SYNONYM dbms_reputil;
  702.  
  703. CREATE PUBLIC SYNONYM dbms_reputil FOR dbms_reputil;
  704.  
  705. GRANT EXECUTE ON dbms_reputil TO PUBLIC;
  706.  
  707.  
  708.